package com.example.transaction.service;

import com.example.transaction.mapper.LogInfoMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

@Service
@Slf4j

public class LogService {
    @Autowired
    private LogInfoMapper logInfoMapper;
    @Transactional(propagation = Propagation.NESTED)
    public void insertLog(String name,String op){
        try{
            int a=10/0;
        }catch (Exception e){
            log.error("异常为，e:",e);
            //手动回滚当前事务
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
        }

        logInfoMapper.insertLog(name,op);
    }

}
